'use strict';

const conn = require('../../../libs/Conn');
const _ = require('underscore');
const util = require('../../../libs/Utils');

module.exports = async function (params) {
    try {
        let checkSql = `SELECT mobile FROM  user_file uf WHERE uf.user_id IN (?)  `;
        let userData = await conn(checkSql,[params.user_id]);
        if (userData.length>0) {
            if(userData[0].mobile){
                let newPassword = util.encrypt(userData[0].mobile.substr(userData[0].mobile.length - 6, 6));
                let updateSql = `UPDATE user_file uf SET password = '${newPassword}' WHERE user_id IN (?)`;
                await conn(updateSql,[params.user_id]);
                return {success: true};
            }else{
                return {success:false}
            }
        }
    } catch (e) {
        return {success: false, message: e};
    }
};